#!/bin/bash 

#目录
VERSION_DIR=/home/epccadmin/update_epcc_version/EPCC_$(date +%Y%m%d)/shfile

#APP1地址
#EPCC_APP1_IP=10.192.00.137
EPCC_APP_IP=$1

#目录
EPCC_APP_DIR=/home/szfb/epcc/EPCC_FB

#菜单显示函数
dispmenu ()
{
        clear
        echo 
        echo -e "\t    ------------------------------------------------------"
        echo -e "\t    |           EPCC 系 统 快 速 部 署                    |"
        echo -e "\t    |         当前操作环境[${EPCC_APP_IP}]                |"
        echo -e "\t    ------------------------------------------------------"
        echo -e 
        echo -e "\t  ----------------------------------------------------------"
        echo -e "\t  |               【1】.  备份并部署                       |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【2】.  停止服务                         |"
        echo -e "\t  |                                                        |"
    echo -e "\t  |               【3】.  启动服务                         |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【4】.  健康检查                         |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【5】.  清理文件                         |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【6】.  版本回退                         |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【7】.  版本全部备份                     |"
        echo -e "\t  |                                                        |"
        echo -e "\t  |               【0】.  退出部署                         |"        
        echo -e "\t  |                                                        |"
        echo -e "\t  ----------------------------------------------------------"
        echo -e        "\t  |            【常规执行序号顺序：1、2、3、4、0】         |"
        echo -e "\t  ----------------------------------------------------------"
        echo -e
        echo -e "\t\t\t  >>> 输入您的选择: \c"
}

#------------------------------------------------
#  主函数入口
#------------------------------------------------
while [ 1 ]
do
        dispmenu
        read ans
        case $ans in
        0)
                exit
                ;;
                
                1)
                clear
                        ssh epccadmin@${EPCC_APP_IP} "sh ${VERSION_DIR}/epcc_update.sh ${EPCC_APP_IP}"
                        echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;
        
        2)
                 clear
                        ssh epccadmin@${EPCC_APP_IP} "sh ${VERSION_DIR}/shutdown.sh ${EPCC_APP_IP}"
                        echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;

        3)
                clear
        ssh epccadmin@${EPCC_APP_IP} "source /home/epccadmin/.bash_profile &&sh ${VERSION_DIR}/startup.sh ${EPCC_APP_IP}"
                echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
                ;;
                                                  
        4)
                clear 
                        ssh epccadmin@${EPCC_APP_IP} "sh ${VERSION_DIR}/check.sh ${EPCC_APP_IP}" 
                        echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;

        5)
                clear
                        ssh epccadmin@${EPCC_APP_IP} "sh ${VERSION_DIR}/delete_his_pkq.sh ${EPCC_APP_IP}"
                        echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;        

                6)
                clear
                        ssh epccadmin@${EPCC_APP_IP} "sh ${VERSION_DIR}/back_pkg_epcc.sh ${EPCC_APP_IP}"
                        echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;
                
                7)
                clear
                        ssh epccadmin@${EPCC_APP_IP} "sh /home/epccadmin/update_epcc_version/epcc_version_bak.sh"
            echo -e "\n\n\t 按Enter键返回主页面...\c"
                read presskey
        ;;
       esac
done